const defaultAPI = 'https://www.ttzxh.icu/api'
// const defaultAPI = 'http://127.0.0.1:8089/api'
const getRequest = (url, data) => {
  const token = wx.getStorageSync('token')
  return new Promise((resolve, reject) => {
    wx.request({
      url: defaultAPI ? defaultAPI + url : url,
      data: data ? data.params : {},
      header: {
        Authorization: token
      },
      success: res => {
        resolve(res)
      },
      fail: res => {
        wx.showToast({
          title: '服务端错误',
          icon: 'error'
        })
      }
    })
  })
}
const postRequest = (url, data) => {
  const token = wx.getStorageSync('token')
  return new Promise((resolve, reject) => {
    wx.request({
      method: 'post',
      url: defaultAPI ? defaultAPI + url : url,
      data,
      header: {
        Authorization: token
      },
      success: res => {
        resolve(res)
      },
      fail: () => {
        wx.showToast({
          title: '服务端错误',
          icon: 'error'
        })
      }
    })
  })
}
const axios = {
  get: getRequest,
  post: postRequest
}
export { defaultAPI }
module.exports.axios = axios
